Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
I have an object in react javascript T[] and need to convert it to Blob

I am creating this js function:

export function convertArrayObjToFileDownload(data, filename, filetype = 'application/octet-stream') {
    const blob = new Blob(data, { type: filetype });
    downloadBlob(blob, filename);
}

data is a custom object array, like {Client: 'My Bank', Tasks: 15, Charge Amount: '$300.00' }.

I am trying to convert this object array to blob. The array could have hundreds of items.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're very close! Here's the problem:

The Blob() constructor accepts an Array as the first parameter:
https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters

And the Array needs to contain a serialized representation of the data you want to store. For a JavaScript object, that's typically JSON. So first convert your data object to a JSON string, and then store that string in the Blob:

const json = JSON.stringify(data);
const blob = new Blob([json], { type: 'text/plain;charset=utf-8' })

Since you'll be storing a string (encoded at UTF-8 by default), I'd recommend using the text/plain;charset=utf-8 MIME type.

Once you download this Blob, it'll be easy to open in any text editor since it's just plaintext.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda